import store from "../store/index";
import Vue from "vue";
export async function JudgeLogin(self) {
  let res = await Vue.prototype.$api
    .post(`${self.zs}/live/user/info`)
    .then(res => {
      let code = res.data.code;
      let email = res.data.data.email;
      let info = res.data.data;
      if (res.data.code == "UnLogin") {
        // this.$message("请先登录");
        self.$router.push("/").catch(err => {
          err;
        });
        store.commit("show", true);
        store.commit("setIsLogin", false);
      } else if (res.data.data.email == "") {
        self.$message({
          message: "请先完成个人认证,填写基本资料",
          type: "error",
          duration: 2000,
          offset: 320
        });

        self.$router.push("/vip").catch(err => {
          err;
        });
      }
      return { code, email, info };
    });
  return res;
}
//文件中使用了ES7的async函数，async函数一旦执行会立即返回一个Promise对象，等待所有await后的异步操作结束后改变Promise的状态
export async function Permission(num, self) {
  let res = await Vue.prototype.$api.post(
    `${self.zs}/ip/access/set?status=${num}`
  );
  return res.data.success;
}
// export function Permission(num, self) {
//   return Vue.prototype.$api
//     .post(`${self.zs}/ip/access/set?status=${num}`)
//     .then(res => {
//       return res.data.success;
//     });
// }
